package com.ccx.coachsite.weibo.auth2.vo;


import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.graphics.Bitmap;
import android.text.TextUtils;

import com.ccx.coachsite.weibo.json.JSONObject;

/**
 * 微博用户信息对象
 * @author Administrator
 *
 */
public class User implements Serializable{

	private static final long serialVersionUID = 608769853850438921L;
	
	/**用户UID*/
	private String uid;
	
	/**用户昵称 */
	private String screenName;
	
	/**友好显示名称 */
	private String name;
	
	/**用户所在地区ID*/
	private int province;
	
	/**用户所在城市ID*/
	private int city;
	
	/**用户所在地  */
	private String location;
	
	/**用户描述 */
	private String description;
	
	/**	用户博客地址*/
	private String url;
	
	/**	用户头像地址 */
	private String profileImageUrl;
	
	/**	用户的个性化域名 */
	private String domain;
	
	/**性别，m：男、f：女、n：未知 */
	private String gender;
	
	/**粉丝数  */
	private long followersCount;
	
	/**	关注数 */
	private long friendsCount;
	
	/**微博数 */
	private long statusCount;
	
	/**	收藏数  */
	private long favouritesCount;
	
	/**	创建时间  */
	private String createdAt;
	
	/**当前登录用户是否已关注该用户  */
	private boolean following;
	
	/**是否允许所有人给我发私信 */
	private boolean allowAllActMsg;
	
	/**是否允许带有地理信息 */
	private boolean geoEnabled;
	
	/**是否是微博认证用户，即带V用户 */
	private boolean verified;
	
	/**是否允许所有人对我的微博进行评论  */
	private boolean allowAllComment;
	
	/**用户大头像地址  */
	private String avatarLarge;
	
	/**认证原因 */
	private String verifiedReason;
	
	/**该用户是否关注当前登录用户 */
	private boolean followMe;
	
	/**用户的在线状态，0：不在线、1：在线  */
	private int onlineStatus;
	
	/**	用户的互粉数 */
	private long biFollowersCount;
	
	/**微博ID，关注用户列表中的用户对象只给出一个ID，需要再次获取转成微博对象*/
	private long weiboId;
	
	/**用户的最近一条微博信息 */
	private Status status;
	
	/**用户信息的JSON数据*/
	private transient JSONObject userJsonObj;
	
	/**用户头像*/
	private transient Bitmap icon;
	
	public User(){}
	
	public User(String jsonString) throws Exception
	{
		try {
			JSONObject jsonObj=new JSONObject(jsonString);
			constructUser(jsonObj);
		} catch (Exception e) {
			throw new Exception("Create user instance failed", e);
		}
	}
	
	public User(JSONObject jsonObj) throws Exception
	{
		try {
			constructUser(jsonObj);
		} catch (Exception e) {
			throw new Exception("Create user instance failed", e);
		}
	}

	/**
	 * 构建用户对象
	 * @param jsonObj
	 */
	private void constructUser(JSONObject jsonObj) throws Exception
	{
		if(jsonObj==null)
			return;
		
		this.userJsonObj=jsonObj;
		
		this.uid=jsonObj.getString("idstr");
		this.screenName=jsonObj.getString("screen_name");
		this.name=jsonObj.getString("name");
		this.province=jsonObj.getInt("province");
		this.city=jsonObj.getInt("city");
		this.location=jsonObj.getString("location");
		this.description=jsonObj.getString("description");
		this.url=jsonObj.getString("url");
		this.profileImageUrl=jsonObj.getString("profile_image_url");
		this.domain=jsonObj.getString("domain");
		this.gender=jsonObj.getString("gender");
		this.followersCount=jsonObj.getLong("followers_count");
		this.friendsCount=jsonObj.getLong("friends_count");
		this.statusCount=jsonObj.getLong("statuses_count");
		this.favouritesCount=jsonObj.getLong("favourites_count");
		
		String UTD_CreateAt=jsonObj.getString("created_at");
		if(!TextUtils.isEmpty(UTD_CreateAt))
		{
			try {
				Date date=new Date(UTD_CreateAt);
				SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
				this.createdAt=sdf.format(date);
			} catch (Exception e) {
				this.createdAt=UTD_CreateAt;
			}
			
		}
		
		this.following=jsonObj.getBoolean("following");
		this.allowAllActMsg=jsonObj.getBoolean("allow_all_act_msg");
		this.geoEnabled=jsonObj.getBoolean("geo_enabled");
		this.verified=jsonObj.getBoolean("verified");
		this.allowAllComment=jsonObj.getBoolean("allow_all_comment");
		this.avatarLarge=jsonObj.getString("avatar_large");
		this.verifiedReason=jsonObj.getString("verified_reason");
		this.followMe=jsonObj.getBoolean("follow_me");
		this.onlineStatus=jsonObj.getInt("online_status");
		this.biFollowersCount=jsonObj.getLong("bi_followers_count");
		this.weiboId=jsonObj.getLong("status_id");
		
		//最近发布的微博
		JSONObject statusJson=jsonObj.getJSONObject("status");
		if(statusJson!=null)
			this.status=new Status(statusJson);
			
	}
	
	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public String getScreenName() {
		return screenName;
	}

	public void setScreenName(String screenName) {
		this.screenName = screenName;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getProvince() {
		return province;
	}

	public void setProvince(int province) {
		this.province = province;
	}

	public int getCity() {
		return city;
	}

	public void setCity(int city) {
		this.city = city;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getProfileImageUrl() {
		return profileImageUrl;
	}

	public void setProfileImageUrl(String profileImageUrl) {
		this.profileImageUrl = profileImageUrl;
	}

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public long getFollowersCount() {
		return followersCount;
	}

	public void setFollowersCount(long followersCount) {
		this.followersCount = followersCount;
	}

	public long getFriendsCount() {
		return friendsCount;
	}

	public void setFriendsCount(long friendsCount) {
		this.friendsCount = friendsCount;
	}

	public long getStatusCount() {
		return statusCount;
	}

	public void setStatusCount(long statusCount) {
		this.statusCount = statusCount;
	}

	public long getFavouritesCount() {
		return favouritesCount;
	}

	public void setFavouritesCount(long favouritesCount) {
		this.favouritesCount = favouritesCount;
	}

	public String getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(String createdAt) {
		this.createdAt = createdAt;
	}

	public boolean isFollowing() {
		return following;
	}

	public void setFollowing(boolean following) {
		this.following = following;
	}

	public boolean isAllowAllActMsg() {
		return allowAllActMsg;
	}

	public void setAllowAllActMsg(boolean allowAllActMsg) {
		this.allowAllActMsg = allowAllActMsg;
	}

	public boolean isGeoEnabled() {
		return geoEnabled;
	}

	public void setGeoEnabled(boolean geoEnabled) {
		this.geoEnabled = geoEnabled;
	}

	public boolean isVerified() {
		return verified;
	}

	public void setVerified(boolean verified) {
		this.verified = verified;
	}

	public boolean isAllowAllComment() {
		return allowAllComment;
	}

	public void setAllowAllComment(boolean allowAllComment) {
		this.allowAllComment = allowAllComment;
	}

	public String getAvatarLarge() {
		return avatarLarge;
	}

	public void setAvatarLarge(String avatarLarge) {
		this.avatarLarge = avatarLarge;
	}

	public String getVerifiedReason() {
		return verifiedReason;
	}

	public void setVerifiedReason(String verifiedReason) {
		this.verifiedReason = verifiedReason;
	}

	public boolean isFollowMe() {
		return followMe;
	}

	public void setFollowMe(boolean followMe) {
		this.followMe = followMe;
	}

	public int getOnlineStatus() {
		return onlineStatus;
	}

	public void setOnlineStatus(int onlineStatus) {
		this.onlineStatus = onlineStatus;
	}

	public long getBiFollowersCount() {
		return biFollowersCount;
	}

	public void setBiFollowersCount(long biFollowersCount) {
		this.biFollowersCount = biFollowersCount;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public JSONObject getUserJsonObj() {
		return userJsonObj;
	}

	public void setUserJsonObj(JSONObject userJsonObj) {
		this.userJsonObj = userJsonObj;
	}
	
	public Bitmap getIcon() {
		return icon;
	}

	public void setIcon(Bitmap icon) {
		this.icon = icon;
	}

	public long getWeiboId() {
		return weiboId;
	}

	public void setWeiboId(long weiboId) {
		this.weiboId = weiboId;
	}
	
	
	
}








